package pkg.dao;

import com.googlecode.objectify.Objectify;

import java.io.Serializable;
import java.util.List;

public abstract class Filter implements Serializable {
    
    private int numRows = 1000;
    private int startRow = 0;
    private boolean unlimited = false;
    private boolean filterSet = false;
    private boolean isAscending = true;
    private String sortColumn;
    private String primaryKeyName;
    protected Objectify ofy;
    
    /**
     * Creates a new instance of Filter
     */
    public Filter() {
    }
    
    public abstract List getElements(Objectify ofy);
    
    public boolean blank(String s) {
        return s == null || s.length() == 0;
    }

    public int getNumRows() {
        return numRows;
    }

    public void setNumRows(int numRows) {
        this.numRows = numRows;
    }

    public boolean isUnlimited() {
        return unlimited;
    }

    public void setUnlimited(boolean unlimited) {
        this.unlimited = unlimited;
    }

    public boolean isFilterSet() {
        return filterSet;
    }

    public void setFilterSet(boolean filterSet) {
        this.filterSet = filterSet;
    }

    public boolean isAscending() {
        return isAscending;
    }

    public void setAscending(boolean ascending) {
        isAscending = ascending;
    }

    public String getSortColumn() {
        return sortColumn;
    }

    public void setSortColumn(String sortColumn) {
        this.sortColumn = sortColumn;
    }

    public String getPrimaryKeyName() {
        return primaryKeyName;
    }

    public void setPrimaryKeyName(String primaryKeyName) {
        this.primaryKeyName = primaryKeyName;
    }

    public int getStartRow() {
        return startRow;
    }

    public void setStartRow(int startRow) {
        if (startRow < 0) {
            startRow = 0;
        }
        this.startRow = startRow;
    }
    
    public abstract int getCount(Objectify ofy);
}
